package io.renren.modules.mapp.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.api.annotation.AuthIgnore;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.mapp.entity.ActivityEntity;
import io.renren.modules.mapp.service.ActivityService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author cyb
 * @email 
 * @date 2017-08-01 12:20:04
 */
@RestController
@RequestMapping("/mapp/activity")
public class ActivityController {
	@Autowired
	private ActivityService activityService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ActivityEntity> activityList = activityService.queryList(query);
		int total = activityService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(activityList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@AuthIgnore
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id){
		ActivityEntity activity = activityService.queryObject(id);
		
		return R.ok().put("activity", activity);
	}
	
	/**
	 * 保存
	 */
	@AuthIgnore
	@RequestMapping("/save")
	public R save(@RequestBody ActivityEntity activity){
		activityService.save(activity);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody ActivityEntity activity){
		activityService.update(activity);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids){
		activityService.deleteBatch(ids);
		return R.ok();
	}
	
}
